package phone.qyg.com.qyg.utils;

import com.app.application.QXApplication;

import org.xutils.DbManager;
import org.xutils.ex.DbException;

import java.util.List;

import phone.qyg.com.qyg.model.Find;


/**
 * 作者：lblbh on 2017/6/5 11:25
 * 邮箱：lanbuhan@163.com
 * 功能：搜索结果工具类
 */
public class FindUtil {

    /**
     * 获取全部搜索结果
     * @return
     */
    public static List<Find> findData(){
        List<Find> models = null;
        DbManager db = QXApplication.getDB();
        try {
            models = db.selector(Find.class)
                    .orderBy("id")
                    .findAll();

        } catch (DbException e) {
            e.printStackTrace();
        }
        return models;
    }


    /**
     * 添加操作
     * @param key
     */
    public static void addFindKey(String key){
        DbManager db = QXApplication.getDB();

        try {
            Find find = db.selector(Find.class).where("key", "=", key).findFirst();
            if(find == null){
                find = new Find(key);
                db.saveBindingId(find);
            }
        } catch (DbException e) {
            e.printStackTrace();
        }

    }


    /**
     * 删除数据库
     */
    public static void deleteFind(){
        DbManager db = QXApplication.getDB();
        try {
            db.delete(Find.class);
        } catch (DbException e) {
            e.printStackTrace();
        }
    }
}
